package com.javaee.controller.doctor;

import com.javaee.BeforeBaseController;
import com.javaee.entity.Doctor;


import com.javaee.service.doctor.DPlanService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.*;

@Controller
@RequestMapping("/doctor")
public class DPlanController extends BeforeBaseController {
    @Autowired
    private DPlanService planService;
    @RequestMapping("/selectMyPlanByPage")
    public String selectMyMzghByPage(Model model, Integer currentPage, HttpSession session) {
        if (currentPage == null){
            currentPage = 1;
        }
        Doctor doctor = (Doctor) session.getAttribute("Doctor");
        int id = doctor.getId();
        int totalCount = planService.selectCount(id);
        int pageSize = 5;
        int totalPage = (int)Math.ceil(totalCount*1.0/pageSize);
        List<Map<String, Object>> planList = planService.findAllWithDoctor((currentPage-1)*pageSize, pageSize, id);
        model.addAttribute("plans",planList);
        model.addAttribute("totalPage", totalPage);
        model.addAttribute("currentPage", currentPage);
        return "doctor/plan";
    }
}

